<!DOCTYPE html>
<html>

<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<meta content="yes" name="apple-mobile-web-app-capable" />
<meta content="black" name="apple-mobile-web-app-status-bar-style" />
<meta content="telephone=no" name="format-detection" />
<meta content="email=no" name="format-detection" />
<link rel="stylesheet" type="text/css" href="static/wap/css/common.css"/>
<script type="text/javascript" src="static/wap/js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="static/wap/js/resize.js"></script>

<body class="bg">
<div class="container">
  <div class="login">
    <img src="https://img.zhiwuyipin.com/10001/20210827/bdfa786156048849147b5e668646788b.png" class="imgResponsive" />
    <input type="hidden" name="referrer_id" value="3304">
    <ul class="ulform">
      <li>
        <label class="lb">
          <i class="icon ic1"></i>
        </label>
        <input type="number" class="inptxt" name="mobile" id="mobile" placeholder="请输入手机号码" />
      </li>
      <li>
        <label class="lb">
          <i class="icon ic2"></i>
        </label>
        <input type="text" class="inptxt inptxt2" id="iCode" placeholder="请输入图形验证码" />
        <img id="imgcode" onclick="cImgCode()" class="btnSend"/>
      </li>
      <li>
        <label class="lb">
          <i class="icon ic3"></i>
        </label>
        <input type="text" class="inptxt inptxt2" name="code" id="code" placeholder="请输入验证码" />
        <input type="text" onclick="getSmsCode(this)" id="getCode" value="获取验证码" class="btnSend" readonly="readonly"/>
      </li>
      <!--<li style="color: #5c5c5c">
        <i>完成实名认证</i>
      </li>-->
      <li>
        <a href="javascript:;" id="phoneAjax" style="color:red"></a>
      </li>
      <li>
        <input type="submit" id="submit" value="注册" class="btnReg" />
      </li>
      <!--<li>
        <a href="down.html" class="btnReg" style="display: block;text-align: center;background: #999;">已注册立即下载</a>
      </li>-->
    </ul>
  </div>
</div>
<script>
  let wait=60;
  function time(o) {
    if (wait === 0) {
      o.removeAttribute("disabled");
      o.value = "获取验证码";
      wait = 60;
    } else {
      o.setAttribute("disabled", true);
      o.value = "重发(" + wait + ")";
      wait--;
      setTimeout(function () {
        time(o)
      },1000)
    }
  }
  //判断是否为手机号的正则表达式
  function phoneFun(phones){
    var myreg = /^[1][3,4,5,7,8,9][0-9]{9}$/;
    if (!myreg.test(phones)) {
      console.log('手机号格式不正确')
      return false;
    } else {
      console.log('手机号格式正确')
      return true;
    }
  }

  // 判断是否为电话号
  function telFun(tels){
    var myreg = /^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/;
    if (!myreg.test(tels)) {
      return false;
    } else {
      return true;
    }
  }
  //验证字符串为空
  function testStrIsEmpty(str){
    return str.length === 0
  }
  //验证身份证是否合规
  function testId(str){
    var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
    return reg.test(str) !== false;
  }
  //获取url get参数
  function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)","i");
    var r = window.location.search.substr(1).match(reg);
    if (r!=null) return (r[2]); return null;
  }

  let pid = GetQueryString('pid') ? GetQueryString('pid'):0

  //获取请求票据
  let captchaKey = ''

  //获取图形验证码
  function cImgCode(){
    $.get('../index.php?s=/api/passport/captcha',r=>{
      if(r.status === 200){
        let imgcode = r.data.base64
        $('#imgcode').attr('src',imgcode)
        captchaKey = r.data.key
      }
    })
  }
  //发送短信验证码
  function getSmsCode(that){
    let iCode = $('#iCode').val()
    let mobile = $('#mobile').val()
    if(iCode===''){
      alert('图形验证码不为空')
      return
    }
    if(mobile===''){
      alert('手机号不为空')
      return
    }
    if(!phoneFun(mobile)){
      alert('手机号格式错误')
      return
    }
    let formData = {
      form:{
        captchaCode : iCode,
        captchaKey:captchaKey,
        mobile:mobile
      }
    }
    $.ajax({
      type: "post",
      url: "../index.php?s=/api/passport/sendSmsCaptcha",
      dataType : "json",
      contentType : "application/json",
      data: JSON.stringify(formData),
      success: function (d) {
        if(d.status === 200){
          //图形验证码发送成功
          time(that)
          console.log('发送验证码成功')
        }else{
          alert(d.message)
        }
      }
    })
  }

  $(()=>{
    cImgCode()
  })

  $('#submit').click(function (){
    //用于提交注册的数据
    let SubData = {
      form:{
        pid:pid,
        isParty:false,
        mobile:$('#mobile').val(),
        smsCode:$('#code').val(),
        platform:'H5',
        partyData:{}
      }
    }
    $.ajax({
      type: "post",
      url: "../index.php?s=/api/passport/login",
      dataType : "json",
      beforeSend:function (req){
        req.setRequestHeader("platform","H5")
      },
      contentType : "application/json",
      data: JSON.stringify(SubData),
      success: function (d) {
        if(d.status === 200){
          alert('成功注册经销商')
        }else{
          alert(d.message)
        }
      }
    })
  })

</script>
</body>
</html>
